package com.clinic.controller;


import com.clinic.entity.ClinicUsers;
import com.clinic.service.ClinicUsersService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;


/**
 * (ClinicUsers)表控制层
 *
 * @author makejava
 * @since 2020-11-12 15:55:15
 */

@Controller
public class ClinicUsersController {
    @Autowired
    private ClinicUsersService usersService;

    @ResponseBody
    @GetMapping("/Users")
    public List<ClinicUsers> getAllUsers(){
        return usersService.getAllUsers();
    }
    @GetMapping("/")
    public String index(){
        return "login";
    }
    @PostMapping("/login")
    public  String login(String username , String password){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(username , password);

        try {
            subject.login(token);
            return "main";
        } catch (AuthenticationException e) {
            e.printStackTrace();
        }
        return "login";
    }
    @GetMapping("/GetUserByCuid")
    @ResponseBody
    public ClinicUsers getUserByCuid(@RequestParam("cuid") int cuid){
        return usersService.queryById(cuid);
    }
//    @PostMapping("/insertUser")
//    @ResponseBody
//    public String insertUser( ClinicUsers users){
//        usersService.insert(users);
//        return "success";
//    }
}